import json



from api.base_service_api import BaseService


class MemberService(BaseService):
    def __init__(self):
        super().__init__()

    def find_by_telephone(self,tel):

        resp=self.dubbo_client.invoke("MemberService","findByTelephone",tel)
        #将字符串转换成json
        if resp=="Failed":
            return None
        else:
            result = json.loads(resp)
            return result
    def add(self,member):
        member["class"]="com.itheima.pojo.Member"
        result=self.dubbo_client.invoke("MemberService","add",member)
        if result=="null":
            return result
        else:
            return False
    def find_member_count_by_months(self,months):
        resp=self.dubbo_client.invoke("MemberService","findMemberCountByMonths",months)
        print(json.loads(resp))

if __name__ == '__main__':
    ms=MemberService()
    member={
        "phoneNumber": "13020220001",
        "name": "xiaoming",
        "password": "123456",
        "birthday": "1990-01-01 10:01:01",
        "regTime": "2020-01-01 10:01:01"
    }
    resp=ms.add(member)
    print(resp)
    #
    months=["2021.9", "2021.10"]
    result=ms.find_member_count_by_months(months)
    print(result)

    tel="13020220001"
    resp1=ms.find_by_telephone(tel)
    print(resp1)